/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package controlador;

import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import modelo.Usuarios;

/**
 *
 * @author Felipe
 */
public class ServletHelper {

    public static boolean validarUsu(HttpServletRequest request, HttpServletResponse response) throws IOException {
        StringBuffer url = request.getRequestURL();
        HttpSession session = request.getSession();
        Usuarios usu = (Usuarios) session.getAttribute("USUARIO");
        if (usu == null) {
            response.sendError(HttpServletResponse.SC_FORBIDDEN, "Favor Inicie Session Antes");
            return false;
        }
        return true;

    }

    public static boolean validarAdmin(HttpServletRequest request, HttpServletResponse response) throws IOException {
        HttpSession session = request.getSession();
        session.removeAttribute("Mensaje");

        Usuarios usu = (Usuarios) session.getAttribute("USUARIO");
        if (usu.getPrivilegios() != 2) {
            response.sendError(HttpServletResponse.SC_NOT_FOUND, "Recurso no existe");
            return false;
        }
        return true;

    }

}
